#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define OJ_TEST 0
#define LOCAL_TEST 0

#define M 1024

static int max(int a, int b){ return a>b?a:b; }
static int min(int a, int b) { return a<b?a:b; }

static void solve(void){
	char line[M];
	int i, len, ans;
	while(gets(line)){
		if(strcmp(line, "0")==0) break;
		len = strlen(line);
		for(ans=0,i=0; i<len; ++i){
			ans += (line[i]-'0')*((1<<(len-i))-1);
		}
		printf("%d\n", ans);
	}
}
#if OJ_TEST
	int main(int ac, char *av[]){
		solve();
		return 0;
	}
#elif  LOCAL_TEST
	void run(void){
		solve();
	}

#else

#endif
